# 屏幕输入的参数，从上游PM获取
param (
    [string]$user="",
    [string]$user_pwd="",
    [string]$Database_Name
)

$DATA_BACKUP_AGENT_HOME = (Get-ChildItem env:DATA_BACKUP_AGENT_HOME).Value
$Location = $DATA_BACKUP_AGENT_HOME + "\DataBackup\ProtectClient\Plugins\GeneralDBPlugin\bin\applications\exchange\ps1_scripts"
Set-Location -Path $Location
[string]$common_file_path = (Get-Location).Path + "\Common.ps1"
[string]$pssession_name = "GetDatabaseDetail"

# 引用Common.ps1
. $common_file_path

# 建立连接
if (!(NewConnection $User $User_Pwd $pssession_name)) {
    return $False
}

$database_detail = Invoke-Command -Session $Session -ScriptBlock {Get-MailboxDatabase -identity $using:Database_Name}
if (!$?) {
    ClosePSSession $pssession_name
    return $False
}
ClosePSSession $pssession_name
return $database_detail | ConvertTo-Json -Compress -Depth 10